// 扩展运算符
<template>
  <div>
    <prism language="javascript">
      let arr = [1, 2, 3, 4, 5, 6];
      let a = [...arr]; //a相当于arr
      console.log(a);
      let b = a;
      a[2] = 100;
      console.log(b[2]);

      let c = [...a, ...arr]; //c是a和arr的和 长度为12
      console.log(c.length);

      let [first, ...rest] = [...arr];
      //first是1 rest是2，3，4，5，6
      console.log(rest[2]);
      a.copyWithin(0, 2, 4); //包括2不包括4
      console.log(a);

      let fr = [2, 2, 10, 5, 4].find(function(v) {
      return v > 3; //在fr里找到大于3的,但默认只返回找到的第一个
      });
      console.log(fr);
      let fr2 = [2, 2, 2, 15, 4].findIndex(function(v) {
      return v > 3; //返回找到的第一个的下标
      });
      console.log(fr2);
    </prism>
    <v-btn
      round
      color="success"
      @click="run"
    >
      RUN
    </v-btn>
  </div>
</template>

<script>
import Prism from "vue-prism-component";
export default {
  components: {
    Prism
  },
  methods: {
    run() {
      let arr = [1, 2, 3, 4, 5, 6];
      let a = [...arr]; //a相当于arr
      console.log(a);
      let b = a;
      a[2] = 100;
      console.log(b[2]);

      let c = [...a, ...arr]; //c是a和arr的和 长度为12
      console.log(c.length);

      let [first, ...rest] = [...arr];
      //first是1 rest是2，3，4，5，6
      console.log(rest[2]);
      a.copyWithin(0, 2, 4); //包括2不包括4
      console.log(a);

      let fr = [2, 2, 10, 5, 4].find(function(v) {
        return v > 3; //在fr里找到大于3的,但默认只返回找到的第一个
      });
      console.log(fr);
      let fr2 = [2, 2, 2, 15, 4].findIndex(function(v) {
        return v > 3; //返回找到的第一个的下标
      });
      console.log(fr2);
    }
  }
};
</script>